home *** CD-ROM | disk | FTP | other *** search
/ Maclife 32 / MACLIFE32.ISO.7z / MACLIFE32.ISO / MACLIFE連載 / DIGITAL DRUG PARADISE / HTML / WAVMOJ.java < prev    next >
Text File  |  1996-11-14  |  6KB  |  143 lines

  1. import java.awt.*;
  2. import java.io.*;
  3. import java.lang.*;
  4. import java.util.*;
  5.  
  6. public class WAVMOJ extends java.applet.Applet implements Runnable{
  7.                                       Thread anim;
  8.                                         String s[];
  9.                                         String param;
  10.                                         int mojisize;
  11.                                        
  12.                                         int xa=0;
  13.                                         int textwidth=0;
  14.                                         int count=0;
  15.                                         int maxmsg;
  16.                                         char aska[];
  17.                            
  18.                                         float f[];
  19.                                         int maxArray=(int)(Math.PI*10*2);
  20.                                         Color color;
  21.                                         Font font;
  22.                                      FontMetrics fm;
  23.                                         Image imgbf;
  24.                                         Graphics grf;
  25.                                         Dimension d;
  26.                     public void init(){
  27.                                     d=size();
  28.                                    xa = d.width;
  29.                                    imgbf=createImage(d.width,d.height);
  30.                                    grf=imgbf.getGraphics();
  31.  
  32.                                     f=new float[maxArray];
  33.                                                   double x=3.1;
  34.                                  for(int i=0; i< maxArray ; i++){
  35.                                                   f[i]=(float)Math.sin(x);
  36.                                                  x -=0.1;
  37.                                  }
  38.                                   param=getParameter("mojisize");
  39.                                   mojisize=(param != null)?Integer.parseInt(param):24;
  40.  
  41.                                   param=getParameter("msgsu");
  42.                                   maxmsg=(param != null)?Integer.parseInt(param):1;
  43.                                   s=new String[maxmsg];
  44.                                     int j=0;
  45.                               do{
  46.                                        param=getParameter("message"+(j+1));
  47.                                    if(param != null){
  48.                                              s[j]=new String(param);
  49.                                     }else{
  50.                                            if(param == null){
  51.                                              s[j]="Welcome! Welcome";
  52.                                             }
  53.                                  maxmsg=j+1;
  54.                                      }
  55.                                 }while(param != null && ++j != maxmsg); 
  56.               }
  57.               public void paint(Graphics g){
  58.                                   grf.setColor(Color.black);
  59.                                   grf.fillRect(0,0,d.width,d.height);
  60.  
  61.                                   
  62.                               
  63.                         int widtt=d.height-3;
  64.                  for(int i=0; i< s[count-1].length(); i++){
  65.  
  66.                             int xm=(int)(Math.random()*10+15*i);
  67.                             int xc=fm.charWidth(s[count-1].length());
  68.  
  69.                             int red=(int)(Math.random()*256);
  70.                             int green=(int)(Math.random()*256);
  71.                             int blue=(int)(Math.random()*256);
  72.                             color=new Color(red,green,blue);
  73.                             grf.setColor(color);
  74.  
  75.                             int uku=0;
  76.                             int yy;
  77.                          if(xa+xc<d.width){
  78.                             if(d.width-xa-i>=0){
  79.                                 uku=(d.width-xa-i)%maxArray;
  80.                              }else{
  81.                                 uku=0;
  82.                              }
  83.                           }
  84.                          yy=(int)(f[uku]*widtt*0.3);
  85.  
  86.                       grf.drawChars(aska,i,1,xa+xm+xc,d.height/2+yy);
  87.                     }
  88.                   g.drawImage(imgbf,0,0,d.width,d.height,this);
  89.                   }
  90.                  public void start(){
  91.                                  anim=new Thread(this);
  92.                                  anim.start();
  93.                   }
  94.                   public void setxa(){
  95.                                 xa=xa-3;
  96.                                if(xa <- textwidth){
  97.                                     xa=d.width;
  98.                                 }
  99.                  }
  100.                   public void run(){
  101.                                     while(true){
  102.                                          preset();
  103.                                          try{
  104.                                               Thread.sleep(100);
  105.                                           }catch(InterruptedException e){};
  106.                                          setxa();
  107.                                        repaint();
  108.                                     }
  109.                     }
  110.                  public void update(Graphics g){
  111.                                    paint(g);
  112.                   }
  113.                  public void preset(){
  114.                          font=new Font("Helvetica",Font.PLAIN,mojisize);
  115.                           grf.setFont(font);
  116.                           if(xa == d.width){
  117.                                  count++;
  118.                                   if(count > maxmsg){
  119.                                        count=1;
  120.                                     }
  121.                             }
  122.                              aska=new char[s[count-1].length()];
  123.                              s[count-1].getChars(0,s[count-1].length(),aska,0);
  124.  
  125.                              fm=grf.getFontMetrics();
  126.                              textwidth=fm.stringWidth(s[count-1]+"");
  127.                   }
  128.                   public void stop(){
  129.                                 if(anim != null){
  130.                                            anim.stop();
  131.                                            anim=null;
  132.                                  }
  133.                    }
  134. }
  135.  
  136.               
  137.  
  138.  
  139.                                  
  140.                                  
  141.                                   
  142.                                     
  143.